<script>
	import { watermark, watermarkSet } from '@/common/utils/waterMark2.js'
	export default {
		onLaunch: function() {
			localStorage.setItem('category', ''); 
			localStorage.setItem('pageDate', ''); 
			// 获取当前时间
			  const today = new Date();
			  function formatDate(date) {
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				return `${year}-${month}-${day}`;
			  }
			  //判断当前时间是否是晚上12点之前
			  function isBeforeMorning2() {
				const now = new Date();
				const hour = now.getHours();
				const minute = now.getMinutes();
			  
				return hour < 12 
			  }
			  //当前日期
			  function getPreviousDay(dateString) {
				const date = new Date(dateString);
				date.setDate(date.getDate());
				return date;
			  }
			   //当前日期的前一天
			  function getPreviousDay2(dateString) {
				const date = new Date(dateString);
				date.setDate(date.getDate() - 1);
				return date;
			  }
			  // const previousDay2 = getPreviousDay(formatDate(today))
			  // localStorage.setItem('pageDate', previousDay2.toISOString().split('T')[0]);  //缓存时间
			  //中午12点之前
			  if(isBeforeMorning2()){
				console.log('中午12点之前')
				const previousDay = getPreviousDay2(formatDate(today))
				localStorage.setItem('pageDate', previousDay.toISOString().split('T')[0]);  //缓存时间
				// localStorage.setItem('category', 2);  //缓存白天还是夜班 1白班 2夜班
			  }else{
				console.log('中午12点之后')
				const previousDay2 = getPreviousDay(formatDate(today))
				localStorage.setItem('pageDate', previousDay2.toISOString().split('T')[0]);  //缓存时间
				// localStorage.setItem('category', 1);  //缓存白天还是夜班 1白班 2夜班
			  }
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide离开')
		},
		watch: {
			'$route': {
				handler (to, form) {
					console.log(to, form ,'aapp===')
					if (to.meta.pagePath === 'pagesJK/H5Login/login' || to.meta.pagePath === 'pages/H5Login/privacyPolicy') {
						console.log(to.path, 'ddddd')
						watermarkSet.setCreateFlag(false)
						watermark.out()
					} else {
						let userName=uni.getStorageSync('userName')
						let phoneNumber=uni.getStorageSync('phoneNumber')
						let time = this.$timeFormat(new Date(), 'yyyy.mm.dd')
						let text = [userName + phoneNumber, time] 
						if (text) {
							watermark.set(text)
							watermarkSet.setCreateFlag(true)
							watermarkSet.text = text
						}
					}
				},
				immediate: true,
				deep: true,
			}
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	uni-page-wrapper {
		background-color: #F5F8FB;
	}
	html{
		touch-action: pan-y;
	}
	/* #ifdef H5 */
	uni-page-head {
	  display: none !important;
	} 
	/* #endif */
</style>
